<template>
  <div>
    <address-head title="地址编辑"></address-head>
    <div class="container">
      <van-address-edit
        :area-list="addressInfo"
        show-postal
        show-set-default
        show-delete
        delete-button-text
        :address-info = 'addressBegin'
        :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave"
        @delete="onDelete"
      />
    </div>
  </div>
</template>

<script>
import AddressHead from '@components/AddressHead'
import { mapState, mapMutations } from 'vuex'
export default {
  data () {
    return {
    }
  },
  computed: {
    addressBegin () {
      return this.contacts[this.$route.params.index]
    },
    ...mapState({
      addressInfo: (state) => state.address.addressInfo,
      contacts: (state) => state.address.contacts
    })
  },
  methods: {
    onSave (add) {
      this.changeConcact({
        index: this.$route.params.index,
        item: add
      })
      this.$router.push('/addressList')
    },
    onDelete () {
      this.deleteConcact(this.$route.params.index)
      this.$router.push('/addressList')
    },
    ...mapMutations('address', ['changeConcact', 'deleteConcact'])
  },
  components: {
    AddressHead
  }
}
</script>

<style lang="scss" scoped>

</style>
